/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HopfieldGUI.java
 *
 * Created on 07/07/2011, 21:00:23
 */

package ia.hopfield.gui;

import Jama.Matrix;
import ia.hopfield.Hopfield;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Neto
 */
public class HopfieldGUI extends javax.swing.JFrame {

    /** Creates new form HopfieldGUI */
    public HopfieldGUI(Hopfield hopfield) {
        initComponents();
        this.hopfield = hopfield;
        configComponents();
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablePadrao1 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTablePadrao2 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTablePadrao3 = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTablePadrao4 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTablePadraoRuidoso = new javax.swing.JTable();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTablePadraoRecuperado = new javax.swing.JTable();
        jComboBoxPadroes = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Parâmetros", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Número de Neuronios:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Função de Ativação:");

        jLabel7.setForeground(new java.awt.Color(102, 102, 255));
        jLabel7.setText("45");

        jLabel8.setForeground(new java.awt.Color(102, 102, 255));
        jLabel8.setText("Sinal");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)))
                .addContainerGap(738, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8))
                .addContainerGap(62, Short.MAX_VALUE))
        );

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "null"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jTablePadrao1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadrao1.setTableHeader(null);
        jScrollPane1.setViewportView(jTablePadrao1);

        jTablePadrao2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadrao2.setTableHeader(null);
        jScrollPane3.setViewportView(jTablePadrao2);

        jTablePadrao3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadrao3.setTableHeader(null);
        jScrollPane4.setViewportView(jTablePadrao3);

        jTablePadrao4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadrao4.setTableHeader(null);
        jScrollPane5.setViewportView(jTablePadrao4);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Padrão 1");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Padrão 2");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Padrão 3");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Padrão 4");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(47, 47, 47)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(138, 138, 138)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jLabel1)
                        .addGap(179, 179, 179)
                        .addComponent(jLabel2)
                        .addGap(184, 184, 184)
                        .addComponent(jLabel3)
                        .addGap(181, 181, 181)
                        .addComponent(jLabel4)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(130, 130, 130)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(447, 447, 447))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addContainerGap(386, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Padrões Armazenados", jPanel2);

        jTablePadraoRuidoso.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadraoRuidoso.setTableHeader(null);
        jScrollPane6.setViewportView(jTablePadraoRuidoso);

        jTablePadraoRecuperado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "bit 0", "bit 1", "bit 2", "bit 3", "bit 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePadraoRecuperado.setTableHeader(null);
        jScrollPane7.setViewportView(jTablePadraoRecuperado);

        jComboBoxPadroes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Padrão 1", "Padrão 2", "Padrão 3", "Padrão 4", "Padrão 5", "Padrão 6", "Padrão 7", "Padrão 8", "Padrão 9", "Padrão 10", "Padrão 11", "Padrão 12" }));
        jComboBoxPadroes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxPadroesActionPerformed(evt);
            }
        });

        jButton2.setText("Recuperar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel9.setText("Imagem com ruído");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel10.setText("Imagem recuperada");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(184, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(183, 183, 183)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jComboBoxPadroes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(297, 297, 297)
                        .addComponent(jButton2)))
                .addGap(165, 165, 165))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(218, 218, 218)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 258, Short.MAX_VALUE)
                .addComponent(jLabel10)
                .addGap(197, 197, 197))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane7, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxPadroes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69))
        );

        jTabbedPane1.addTab("Reconhecimento", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16))
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        imprimirPadraoRecuperado();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jComboBoxPadroesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPadroesActionPerformed
        imprimirPadraoRuidoso();
        clearTabelaRecuperado();
    }//GEN-LAST:event_jComboBoxPadroesActionPerformed

    /**
    * @param args the command line arguments
    */
    private void configComponents()
    {
        jTablePadrao1.setDefaultRenderer(Object.class, new CellRenderer());
        jTablePadrao2.setDefaultRenderer(Object.class, new CellRenderer());
        jTablePadrao3.setDefaultRenderer(Object.class, new CellRenderer());
        jTablePadrao4.setDefaultRenderer(Object.class, new CellRenderer());
        jTablePadraoRuidoso.setDefaultRenderer(Object.class, new CellRenderer());
        jTablePadraoRecuperado.setDefaultRenderer(Object.class, new CellRenderer());
        initTabelaRuidos();
        initTabelaRecuperado();
        imprimirPadraoRuidoso();
    }

    public void imprimirPadrao1()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadrao1.getModel();
        Matrix matriz = hopfield.getArquivoPadroes().getPadrao(0);

        int count = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                }
                modelo.addRow(linhaStr);
                count = 0;
            }
        }
    }

    public void imprimirPadrao2()
    {   
        DefaultTableModel modelo = (DefaultTableModel) jTablePadrao2.getModel();
        Matrix matriz = hopfield.getArquivoPadroes().getPadrao(1);

        int count = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                }
                modelo.addRow(linhaStr);
                count = 0;
            }
        }
    }

    public void imprimirPadrao3()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadrao3.getModel();
        Matrix matriz = hopfield.getArquivoPadroes().getPadrao(2);

        int count = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                }
                modelo.addRow(linhaStr);
                count = 0;
            }
        }
    }

    public void imprimirPadrao4()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadrao4.getModel();
        Matrix matriz = hopfield.getArquivoPadroes().getPadrao(3);

        int count = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                }
                modelo.addRow(linhaStr);
                count = 0;
            }
        }
    }

    public void imprimirPadraoRuidoso()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRuidoso.getModel();

        Matrix matriz = hopfield.getArquivoRuidos().getPadrao(padraoComboBox() - 1);

        int count = 0, linhaTabela = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                    imprimirLinhaPadraoRuidoso(linhaStr, linhaTabela);
                }
                count = 0;
                linhaTabela++;
            }
        }
    }

    private void clearTabelaRecuperado()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRecuperado.getModel();

        for (int i = 0; i < jTablePadraoRecuperado.getRowCount(); i++) {
            for (int j = 0; j < jTablePadraoRecuperado.getColumnCount(); j++) {
                modelo.setValueAt("", i, j);
            }
        }
    }

     public void imprimirPadraoRecuperado()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRuidoso.getModel();

        Matrix matriz_ruidosa = hopfield.getArquivoRuidos().getPadrao(padraoComboBox() - 1);
        Matrix matriz = hopfield.recuperarPadrao(matriz_ruidosa);

        int count = 0, linhaTabela = 0;
        double[] linha = new double[5];
        String[] linhaStr = new String[5];

        for (int i = 0; i < matriz.getRowDimension(); i++) {
            linha[count] = matriz.get(i, 0);
            count++;
            if (count == 5) {
                for (int j = 0; j < linha.length; j++) {
                    if (linha[j] == -1) {
                        linhaStr[j] = "";
                    } else if (linha[j] == 1) {
                        linhaStr[j] = "#";
                    }
                    imprimirLinhaPadraoRecuperado(linhaStr, linhaTabela);
                }
                count = 0;
                linhaTabela++;
            }
        }
    }

    private void imprimirLinhaPadraoRuidoso(String[] cells, int linha)
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRuidoso.getModel();

        for (int i = 0; i < cells.length; i++) {
            modelo.setValueAt(cells[i], linha, i);
        }
    }

    private void imprimirLinhaPadraoRecuperado(String[] cells, int linha)
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRecuperado.getModel();

        for (int i = 0; i < cells.length; i++) {
            modelo.setValueAt(cells[i], linha, i);
        }
    }


    private void initTabelaRuidos()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRuidoso.getModel();

        for (int i = 0; i < 9; i++) {
            modelo.addRow(new String[] {"","","","",""});
        }
    }

    private void initTabelaRecuperado()
    {
        DefaultTableModel modelo = (DefaultTableModel) jTablePadraoRecuperado.getModel();

        for (int i = 0; i < 9; i++) {
            modelo.addRow(new String[] {"","","","",""});
        }
    }

    private int padraoComboBox()
    {
        String str = (String) jComboBoxPadroes.getSelectedItem();
        return Integer.parseInt(str.substring(7));
    }


//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new HopfieldGUI().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBoxPadroes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTablePadrao1;
    private javax.swing.JTable jTablePadrao2;
    private javax.swing.JTable jTablePadrao3;
    private javax.swing.JTable jTablePadrao4;
    private javax.swing.JTable jTablePadraoRecuperado;
    private javax.swing.JTable jTablePadraoRuidoso;
    // End of variables declaration//GEN-END:variables
    private Hopfield hopfield;


}
